﻿using System;
using System.Text;
using System.Data;
using System.Web.UI.HtmlControls;

namespace LKCMS.Web
{
    public partial class DetailTW : System.Web.UI.Page
    {
        public int Id;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!int.TryParse(Request.Params["id"] as string, out this.Id))
            {
                JscriptMsg(300, 120, "错误提示", "<div style=\" padding:5px 5px 5px 5px; text-align:left;line-height:30px;\"><b>亲爱访友：</b><br/>&nbsp;&nbsp&nbsp;&nbsp;<span style=\"color:#FBF204;\">您要打开的信息不存在或参数不正确。<span/><br/></div><div style=\"text-align:center;\"><a href=\"Index.aspx\">跳转到首页</a></div>");
                return;
            }
            if (!Page.IsPostBack)
            {
                Bind(this.Id);
            }
        }


        private void BindMeta(string classname)
        {
            LKCMS.Model.WebSet webset = new LKCMS.BLL.WebSet().loadConfig(LKCMS.Common.Utils.GetXmlMapPath("Configpath"));

            Page.Title = classname + "_" + webset.WebKeywords;


            //Encode/Content type
            HtmlMeta encode = new HtmlMeta();
            encode.HttpEquiv = "Content-Type";
            encode.Content = "text/html; charset=utf-8";
            Page.Header.Controls.Add(encode);

            //Language
            HtmlMeta lang = new HtmlMeta();
            lang.HttpEquiv = "Content-Language";
            lang.Content = "zh-cn";
            Page.Header.Controls.Add(lang);

            //Description
            HtmlMeta desc = new HtmlMeta();
            desc.Name = "Description";
            desc.Content = webset.WebDescription;
            Page.Header.Controls.Add(desc);

            //Keyword
            HtmlMeta keywords = new HtmlMeta();
            keywords.Name = "keywords";
            keywords.Content = webset.WebKeywords;
            Page.Header.Controls.Add(keywords);

        }
        /// <summary>
        /// 遮罩提示窗口
        /// </summary>
        /// <param name="w">宽度</param>
        /// <param name="h">高度</param>
        /// <param name="msgtitle">窗口标题</param>
        /// <param name="msgbox">提示文字</param>
        /// <param name="url">返回地址</param>
        /// <param name="msgcss">CSS样式</param>
        private void JscriptMsg(int w, int h, string msgtitle, string msgbox)
        {
            string msbox = "";
            msbox += "<script src=\"Js/jsmsg.js\" type=\"text/javascript\"></script>\n";
            msbox += "<script type=\"text/javascript\">\n";

            msbox += "alertWin('" + msgtitle + "','" + msgbox + "'," + w + "," + h + ");";
            msbox += "</script>";
            this.Literal2.Text = msbox;

        }
        private void Bind(int id)
        {
            StringBuilder sb = new StringBuilder();
            StringBuilder sb1 = new StringBuilder();
            LKCMS.BLL.Channel bll = new LKCMS.BLL.Channel();
            LKCMS.BLL.Pictures pll = new LKCMS.BLL.Pictures();
           // LKCMS.BLL.Article all = new LKCMS.BLL.Article();

            LKCMS.Model.Pictures amodel = pll.GetModel(id);
            BindMeta(amodel.Title);
            LKCMS.Model.Channel model = bll.GetModel(amodel.ClassId);
            LKCMS.Model.Channel model1 = bll.GetModel(model.ParentId);


            // string typename = model.Title;
            lbtitle.Text = model1.Title;
            DataTable dt = bll.GetListNew(" ParentId=" + model.ParentId);

            //string urladd ="DetailWB.aspx";
            //if (dt.Rows.Count> 0)
            //{

            //    if (urladd != string.Empty)
            //    {
            //最近更新
            sb.Append("<div class=\"right_block\">");
            sb.Append("<div class=\"right_block_title\">");
            sb.Append("<div class=\"left_block_title_text\"><strong>" + model1.Title + "</strong>最近更新</div>");
            sb.Append("</div>");
            sb.Append("<div class=\"right_block_content\">");
            sb.Append("<ul>");

            string s = bll.GetChannels(model.ParentId).ToString();
            if (s != "")
            {

                DataTable dtzj = pll.GetList(15, " ClassId in (" + s + ")", " AddTime desc,Click desc").Tables[0];
                foreach (DataRow dr1 in dtzj.Rows)
                {
                    sb.Append("<li>. <a href=\"DetailTW.aspx?id=" + dr1["ID"].ToString() + "\" title=\"" + dr1["Title"].ToString() + "/ " + dr1["AddTime"].ToString() + "\" target=\"_blank\">" + dr1["Title"].ToString() + "</a></li>");
                }
            }
            sb.Append(" </ul>");
            sb.Append("</div>");
            sb.Append("</div>  ");

            //最热
            sb.Append("<div class=\"right_block\">");
            sb.Append("<div class=\"right_block_title\">");
            sb.Append("<div class=\"left_block_title_text\"><strong>" + model1.Title + "</strong>热点</div>");
            sb.Append("</div>");
            sb.Append("<div class=\"right_block_content\">");
            sb.Append("<ul>");

            // s = bll.GetChannels(model.ParentId).ToString();
            if (s != "")
            {
                DataTable dtzr = pll.GetList(15, " ClassId in (" + s + ")", " Click desc,AddTime desc").Tables[0];
                foreach (DataRow dr2 in dtzr.Rows)
                {
                    sb.Append("<li>. <a href=\"DetailTW.aspx?id=" + dr2["ID"].ToString() + "\" title=\"" + dr2["Title"].ToString() + "/ " + dr2["Click"].ToString() + " Hits\" target=\"_blank\">" + dr2["Title"].ToString() + "</a></li>");
                }
            }
            sb.Append(" </ul>");
            sb.Append("</div>");
            sb.Append("</div>  ");
            this.LiteraClassType.Text = sb.ToString();


            int nor = amodel.ClassId;
            int big = bll.GetModel(nor).ParentId;
            int bigb = bll.GetModel(big).ParentId;

            sb1.Append(" <a href=\"Index.aspx\">网站首页</a> > ");
            sb1.Append(" <a href=\"BigType.aspx?id=" + bigb + "\">" + bll.GetChannelTitle(bigb) + "</a>");
            sb1.Append(" > <a href=\"NormalType.aspx?id=" + big + "\">" + bll.GetChannelTitle(big) + "</a> >  ");
            sb1.Append(" <strong>" + bll.GetChannelTitle(nor) + "</strong> ");
            this.Literaldh.Text = sb1.ToString();

            //}
            //GetData(model.Id);
            pll.UpdateField(id, "Click=" + (amodel.Click + 1));




            this.LiteralTtle1.Text = "<span class=\"add_ons\">&nbsp;</span><span style=\"font-size:16px;\">" + amodel.Title + "</span> ";


             

            StringBuilder sbtitle=new StringBuilder();

            sbtitle.Append("<div id=\"three_pics\">");
            sbtitle.Append("<ul id=\"index_sort\" style=\" background-color:#000000 \">");
            sbtitle.Append("<li><img width=\"146\" height=\"71\" alt=\""+amodel.Title+"\" src=\""+amodel.ImgUrl+"\"  ></li>");
            sbtitle.Append("</ul></div>");
            sbtitle.Append("<div class=\"detail_price_block\" style=\" height:80px;\">");
            sbtitle.Append("<div style=\"float:left; width:450px; margin-left:5px; background-color: #3A7EBD; height:80px;\">");
            sbtitle.Append("<div style=\"margin-left:5px; font-size:14px;   \">  ");
            sbtitle.Append("<span style=\"font-size:15px; font-family: '黑体'; font-weight:bold; color:#FFFFFF;\"> "+amodel.Title+"</span>  ");
            sbtitle.Append(" </div>");
            sbtitle.Append("<div style=\"width:290px; float:left; line-height:45px;\"> <span style=\"font-size:12px; margin-left:5px; \"> RMB  "+amodel.Price.ToString("f2")+"元/人</span></div>");
            sbtitle.Append("<div style=\"float:right;\" ><a style=\"margin-right:5px;\" href=\"book.aspx?line="+System.Web.HttpUtility.HtmlEncode(amodel.Title)+"\">");
            sbtitle.Append("<img src=\"images/bott.jpg\"  border=\"0\" style=\"\"/></a>　　　</div>");
            sbtitle.Append("  </div>");
            sbtitle.Append("</div> ");
            this.LiteralTitle.Text=sbtitle.ToString();




  

　　　　



 







            //this.LiteralTitle.Text = "<div style=\" text-align:center;\"><span style=\" font-size:24px;  font-weight:bold;\">" + amodel.Title + "</span> </div><div style=\" text-align:center;\"><span >来源：" + amodel.Click + "&nbsp;&nbsp;发布时间：" + amodel.AddTime.ToString() + "&nbsp;&nbsp;点击量：" + amodel.Click.ToString() + " Hits</span> </div>";
            this.LiteralContent.Text = amodel.Content;
            this.LiteralBook.Text = "<a href=\"book.aspx?line=" + System.Web.HttpUtility.HtmlEncode(amodel.Title) + "\"><img src=\"images/yudin.jpg\" /></a>";

            // string qyp = string.Empty;
            // string qypid = string.Empty;
            // string hyp = string.Empty;
            // string hypid = string.Empty;
            StringBuilder pagestr = new StringBuilder();

            DataTable pp = pll.GetList(1, "ID <" + id + " and ClassId=" + amodel.ClassId, "SortId asc,AddTime desc").Tables[0];//上一篇
            if (pp.Rows.Count > 0)
            {
                pagestr.Append("<a href=\"DetailTW.aspx?id=" + pp.Rows[0]["ID"].ToString() + "\">上一篇</a> ：" + pp.Rows[0]["Title"].ToString());
            }
            else
            {
                // pagestr.Append("上一篇 ：");
                pagestr.Append("<a title=\"文章类最顶端\">下一篇：&nbsp;&nbsp;&nbsp;&nbsp;</a> ");
            }
            pagestr.Append("&nbsp;&nbsp;|&nbsp;&nbsp;");
            DataTable pn = pll.GetList(1, "ID >" + id + " and ClassId=" + amodel.ClassId, "SortId asc,AddTime desc").Tables[0];//下一篇

            if (pn.Rows.Count > 0)
            {
                pagestr.Append(pn.Rows[0]["Title"].ToString() + "<a href=\"DetailTW.aspx?id=" + pn.Rows[0]["ID"].ToString() + "\">：下一篇</a>");
            }
            else
            {
                // pagestr.Append("上一篇 ：文章类最末端");
                pagestr.Append("&nbsp;&nbsp;&nbsp;&nbsp;<a title=\"文章类最末端\">上一篇：</a> ");

            }

            this.LiteralPage.Text = pagestr.ToString();

            //}

        }
    }
}
